package cn.jinjimi.app.custom.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import cn.jinjimi.app.R;
import cn.jinjimi.app.entity.PhotoInfo;
import cn.jinjimi.app.entity.PictureShow;
import cn.jinjimi.app.managers.OpenActivityManager;
import cn.jinjimi.app.main.adapter.extend.MyBaseAdapter;
import cn.jinjimi.app.main.widget.FrescoImageView.FrescoImageView;

import java.util.List;

/**
 * Created by Roy
 * Date: 16/6/12
 */
public class CustomInfoPhotoPreViewAdapter extends MyBaseAdapter<PhotoInfo> {
    private Context mContext;

    public CustomInfoPhotoPreViewAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final PhotoInfo photoInfo = getItem(position);
        final PhotoHolder holder;

        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_custom_info_photo_pre, null);
            holder = new PhotoHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (PhotoHolder) convertView.getTag();
        }

        holder.image.loadView(photoInfo.getThumbnail_url());
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<PictureShow> pictureShows = PictureShow.createPhotoPreviewShows(getItems(), holder.image);
                OpenActivityManager.getInstance().startPhotoNormalBrowserActivity(mContext, pictureShows, position);

            }
        });

        return convertView;
    }

    public class PhotoHolder {
        public FrescoImageView image;

        public PhotoHolder(View view) {
            image = (FrescoImageView) view.findViewById(R.id.item_image);
        }
    }
}
